#include "Ground.h"

Ground::Ground(Model *model, Texture *texture, Managers *managers)
{
	this ->model = model;
	this ->texture = texture;
	this ->managers = managers;

	fpSpecular = managers ->pixelShaderMan ->Get("specular");

	this ->horiShift = 0.1f;
	this ->depthShift = 0.1f;
}

void Ground::Process(float ms)
{
	model ->Process(ms);

	horiShift += ms / 945.0f;
	depthShift += ms / 689.0f;
}

void Ground::Render()
{
	glPushMatrix();
	glPushAttrib(GL_ENABLE_BIT);

	glEnable(GL_ALPHA_TEST);

	/*if (texture != NULL)
	{
		glEnable(GL_TEXTURE_2D);
		texture ->BindTexture();
	}
	else
		glDisable(GL_TEXTURE_2D);*/

	//fpSpecular ->d

	cgGLSetTextureParameter(cgGetNamedParameter(fpSpecular ->GetProgram(), "tex0"), texture ->GetId());
	cgGLEnableTextureParameter(cgGetNamedParameter(fpSpecular ->GetProgram(), "tex0"));

	float xs = sinf(horiShift) * 0.04f;
	float zs = cosf(depthShift) * 0.04f;

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHTING);

	float amb[4] = {1.0f, 1.0f, 1.0f, 1.0f};
	float dis[4] = {1.0f, 1.0f, 1.0f, 1.0f};

	//glLightfv(GL_LIGHT0, GL_POSITION, l_pos);
	glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, dis);

	texture ->BindTexture();

	/*cgGLDisableProfile(CG_PROFILE_VP30);
	cgGLDisableProfile(CG_PROFILE_FP30);*/

	/*for (float i = 0.1f; i < 0.55f; i += 0.14f)
	{
		glAlphaFunc(GL_GREATER, i);
		model ->Render();
		glTranslatef(xs, 0.5f, zs);
	}*/

	model ->Render();

	glPopAttrib();
	glPopMatrix();
}